package com.imy.touch.runnable;

import android.accessibilityservice.AccessibilityService;
import android.accessibilityservice.GestureDescription;
import android.graphics.Path;
import android.os.Build;
import android.os.SystemClock;

import com.imy.common.util.ALog;
import com.imy.touch.TouchCore;
import com.imy.touch.bean.GesturePoint;

public class LongClickedGestureRunnable extends BaseGestureRunnable implements Runnable {
  public LongClickedGestureRunnable(GesturePoint point) {
    super(point);
  }

  @Override
  public void run() {
    if (checkUserRoot()) {
      down4Root();
      SystemClock.sleep(600);
      up4Root();
    }else {
      longClicked4Accessibility();
    }
  }
  private void  longClicked4Accessibility(){
    if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.N){
      Path mPath=new Path();
      mPath.moveTo(mPoint.x,mPoint.y);
      GestureDescription.Builder builder = new GestureDescription.Builder();
      long clickTime=600L;
      builder.addStroke(new GestureDescription.StrokeDescription(mPath,0,clickTime));
      TouchCore.get().getCallService().getService().dispatchGesture(builder.build(),
          new AccessibilityService.GestureResultCallback() {
            @Override
            public void onCompleted(GestureDescription gestureDescription) {
              ALog.i(" long clicked onCompleted");
            }
            @Override
            public void onCancelled(GestureDescription gestureDescription) {
              ALog.i("long clicked onCancelled");
            }
          },null);
    }else {
      unSupportVer();
    }
  }

}

